package org.footito.android.tools;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.Log;

public class VersionAndScreenSize {

	public static boolean areFragmentsSupported() throws NoClassDefFoundError {
		return (isHoneycomOrOlder());
	}

	public static boolean isHoneycomOrOlder() {
		return Build.VERSION.SDK_INT > 10;
	}

	public static boolean isICSOrOlder() {
		return Build.VERSION.SDK_INT > 13;
	}

	public static boolean isLarge(Context context) {
		try {
			return ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
		} catch (Exception e) {
			Log.e("Exception", e.getClass().toString() + ": " + e.getMessage());
			return false;
		}
	}

	public static boolean isLargeOrUpper(Context context) {
		try {
			boolean resLarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
			boolean resXLarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
			return resLarge || resXLarge;
		} catch (Exception e) {
			Log.e("Exception", e.getClass().toString() + ": " + e.getMessage());
			return false;
		}
	}

	public static boolean isXlarge(Context context) {
		try {
			return ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
		} catch (Exception e) {
			Log.e("Exception", e.getClass().toString() + ": " + e.getMessage());
			return false;
		}
	}

	public static boolean isFroyoOrUpper() {
		return Build.VERSION.SDK_INT >= 8;
	}

	public static boolean isFroyoOrLower() {
		return Build.VERSION.SDK_INT <= 8;
	}
}